package org.springblade.modules.app.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springblade.core.boot.ctrl.BladeController;
import org.springblade.core.mp.support.Condition;
import org.springblade.core.mp.support.Query;
import org.springblade.core.tool.api.R;
import org.springblade.core.tool.utils.Func;
import org.springblade.modules.app.entity.Advertise;
import org.springblade.modules.app.service.IAdvertiseService;
import org.springblade.modules.system.service.IDeptService;
import org.springblade.modules.system.service.IUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;


@RestController
@RequestMapping("blade-app/advertise")
public class AdvertiseController extends BladeController {


	@Autowired
	private IAdvertiseService advertiseService;

	@Autowired
	private IUserService userService;

	@Autowired
	private IDeptService deptService;


	@GetMapping("/detail")
	public R<Advertise> detail(Advertise advertise) {
		Advertise detail = advertiseService.getOne(Condition.getQueryWrapper(advertise));
		return R.data(detail);
	}

	@GetMapping("/list")
	public R<IPage<Advertise>> list(Page page, Advertise params) {
		IPage<Advertise> result = advertiseService.page(page, Wrappers.query(params));
		return R.data(result);
	}


	@GetMapping("/page")
	public R<IPage<Advertise>> page(Advertise advertise, Query query) {
		IPage<Advertise> pages = advertiseService.selectAdvertisePage(Condition.getPage(query), advertise);
		return R.data(pages);
	}


	@PostMapping("/save")
	public R save( @RequestBody Advertise advertise) {
		return R.status(advertiseService.save(advertise));
	}


	@PostMapping("/update")
	public R update(@RequestBody Advertise advertise) {
		return R.status(advertiseService.updateById(advertise));
	}

	@PostMapping("/submit")
	public R submit( @RequestBody Advertise advertise) {
		return R.status(advertiseService.saveOrUpdate(advertise));
	}


	@PostMapping("/remove")
	public R remove(@RequestParam String ids) {
		return R.status(advertiseService.removeByIds(Func.toLongList(ids)));
	}


}
